﻿using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Threading.Tasks;
using KC.Framework.Tenant;
using KC.Model.Account;

namespace KC.DataAccess.Account.Repository
{
    public interface IUserRepository: Microsoft.AspNetCore.Identity.IUserStore<User>
    {
        IList<User> FindAllDetailUsers(bool isApproved = true);
        IList<User> FindAllSimpleUsers();
        IList<User> FindUsersByNames(List<string> names);
        IList<User> FindUsersByEmails(List<string> emails);
        IList<User> FindUsersByIds(List<string> ids);
        IList<User> FindUsersWithOrgsByIds(List<string> ids);
        IList<User> FindUsersByOrgIds(List<int> origIds);
        IList<User> FindUsersByRoleIds(List<string> roleIds);

        Task<IList<Role>> FindRolesByRoleIdsAysnc(List<string> roleIds);

        Tuple<int, IList<User>> FindPagenatedUsersByFilter(int pageIndex, int pageSize, Expression<Func<User, bool>> predicate, string sortProperty, bool ascending = true, bool paging = true);
        Tuple<int, IList<User>> GetPaginatedUsersByOrgIds(int pageIndex, int pageSize, List<int> origIds);
        Task<User> FindByPhoneAsync(string phone);
        User FindByUserId(string id);
        User FindByWxOpenId(string openId);
        Task<User> FindByWxOpenIdAsync(string openId);

        Task<User> GetUserByFilterAsync(Expression<Func<User, bool>> predicate);
        User GetUserWithOrgsAndRolesById(string userId);

        bool AddUsers(List<User> users, bool isSave = true);
        Task<bool> ExistUserByFilterAsync(Expression<Func<User, bool>> predicate);

        bool RemoveUserById(string userId, string operatorId, string operatorName, Guid appId);
        bool SaveRoleInUser(string id, List<string> newIds, string operatorId, string operatorName);
        bool UpdateUser(User user, List<int> newOrgIds = null, bool isSave = true);
        bool UpdateUserInOrganizations(List<int> newIds, string userId, bool isSave = true);
    }
}